<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?= $page_title ?></title>
  <?php include(APPLICATION_BASE_TPL_PATH . "/inc/include.phtml"); ?>
  <!--include-wechat-start-->
  <?php include(APPLICATION_BASE_TPL_PATH . "/inc/include_wechat.phtml"); ?>
  <!--include-wechat-end-->
</head>
<body>
<div id="wrapper">
  <?php echo $menuview; ?>
  <div id="page-wrapper" style="min-height:100%;">
    <div class="row">
      <div class="panel panel-primary">
        <div class="panel-heading">
          <h3 class="panel-title"><?= $page_header ?></h3>
        </div>
        <div class="panel-body" style="display: none">
          <form class="form-horizontal" name="filter">
          </form>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="alert alert-wechat alert-info alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span
              class="sr-only">Close</span></button>

        <p><span class="glyphicon glyphicon-info-sign"></span>
          目前公众号在conf\security\ENV\wechat.php中配置,可以通过\Ext\Wechat\Util\AccountConfigurator中提供的方法获取.</p>

        <p><span class="glyphicon glyphicon-info-sign"></span>
          和Admin模块一致,必须有缓存啊!</p>

      </div>

      <div class="alert alert-wechat alert-warning alert-dismissible" role="alert">
        <span class="glyphicon glyphicon-info-sign"></span>
        当前处理的公众号是<strong><?= $handling ?></strong>.
      </div>

      <div class="panel panel-condensed panel-default panel-hover">
        <div class="panel-heading">
          <h5 class="panel-title">
            <span class="glyphicon glyphicon-list"></span>
            <?= $page_header ?>
          </h5>
        </div>
        <table class="table table-condensed table-bordered table-th-left table-td-right table-of-hidden table-hover">
          <thead>
          <tr>
            <th>名称</th>
            <th>微信号</th>
            <th>AppID</th>
            <th>Token</th>
            <th>EncodingAESKey</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody>
          <?php foreach ($list as $index => $account): ?>
            <tr>
              <td><?= $account['name'] ?></td>
              <td><?= $account['account'] ?></td>
              <td><?= $account['app_id'] ?></td>
              <td><?= $account['token'] ?></td>
              <td><?= $account['aes_key'] ?></td>
              <td style="text-align: left">
                <a role="button" data-toggle="modal" data-target="#<?= $account['account'] ?>"
                   class="show-detail btn btn-xxs btn-primary"><span class="glyphicon glyphicon-zoom-in"></span></a>
                <?php if (!$account['handling']): ?>
                  <a role="button" data-account="<?= $account['account'] ?>"
                     class="set-handling-account btn btn-xxs btn-primary"><span
                        class="glyphicon glyphicon-pushpin"></span></a>
                <?php endif; ?>
              </td>
            </tr>
          <?php endforeach; ?>
          </tbody>
        </table>
      </div>
    </div>


    <div class="row" style="display: none">
      <pre><?php #var_export($list); ?></pre>
      <pre><?php #var_export($_SESSION); ?></pre>

    </div>
    <!-- /#page-wrapper -->

  </div>
  <!-- /#wrapper -->

  <?php foreach ($list as $index => $account): ?>
    <div class="modal fade" id="<?= $account['account'] ?>" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
              <span aria-hidden="true">&times;</span>
              <span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title">公众号<?= $account['account'] ?>的配置</h4>
          </div>
          <div class="modal-body" style="padding: 0">
            <pre style="border:none;margin:0;"><?php var_export($account); ?></pre>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          </div>
        </div>
      </div>
    </div>
  <?php endforeach; ?>


  <div class="modal fade" tabindex="-1" id="modal-set-handling-account" role="dialog">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">设置为处理中的公众号</h4>
        </div>
        <div class="modal-body">
          <div class="modal-loading clearfix" style="display: none;">
            <div class="spinner float-left"></div>
            <div class="modal-loading-message float-left">正在设置,请稍候……</div>
          </div>
          <div class="modal-message" style="display: none;"></div>
          <div class="modal-inner-content">
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        </div>
      </div>
    </div>
  </div>


</body>
<script type="text/javascript">
  (function ($) {
    $('.set-handling-account').modalExt({
      modal: 'modal-set-handling-account',
      show: false,
      data: $(this).data(),
      uri_base: '',
      api: {
        set: ['POST', '<?php echo APP_ADMIN_PATH; ?>/wechat/oaSetHandling']
      },
      button: {
        confirm: {
          title: '确定',
          style: 'primary',
          callback: function (ModalExt) {
            ModalExt.request(
                'set',
                {account: ModalExt.getData('account')},
                {
                  success: function (res) {
                    ModalExt.displayLoading(false).setButtons('ok');
                    if (!res.retcode || 2000000 == res.retcode) {
                      ModalExt.displayMessage('操作成功!');
                    } else {
                      ModalExt.displayMessage(res.msg);
                    }
                  }
                }
            );
          }
        },
        cancel: {
          title: '取消',
          style: 'default',
          dismiss: true
        },
        ok: {
          title: '确定',
          style: 'primary',
          callback: function () {
            window.location.reload();
          }
        }
      },
      callback: {
        init: function (ModalExt, modal_event) {
        },
        show: function (modalExt) {
          var account = modalExt.getData('account');
          modalExt
              .setButtons(['confirm', 'cancel'])
              .displayContent('确定将公众号' + account + '设置为操作中的账号么?<br><br>如果"确定",则此后所有操作都将应用至此账号,除非修改操作中的账号.');
        }
      }
    });
  }(jQuery));
</script>
</html>
